import { fileURLToPath, URL } from 'node:url'

import { defineConfig,loadEnv  } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import ElementPlus from 'unplugin-element-plus/vite'
// https://vitejs.dev/config/
export default ({mode}:any)=>defineConfig({
  plugins: [vue(),  ElementPlus({
    // options
  }),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    proxy: {
      // 选项写法
      '/api': {
        target: loadEnv(mode, process.cwd()).VITE_REQUSETHTTP,    //实际请求的接口地址,该处使用了环境变量
        changeOrigin: true,             //是否伪装
        rewrite: (path) => path.replace(/^\/api/, '')
      },
    }
  },
  css: {
    // css预处理器
    preprocessorOptions: {
      less: {
        charset: false,
        additionalData: '@import "./src/assets/css/index.less";',
      },
    },
  },
})
